package com.shenbianyun.ycx;

import com.alibaba.fastjson.JSONObject;
import com.shenbianyun.bosskgpay.entity.Merchant;
import com.shenbianyun.bosskgpay.entity.RequestMessage;
import com.shenbianyun.bosskgpay.entity.sign.UserSignQueryReqModel;
import com.shenbianyun.bosskgpay.service.sign.TestUserSignQueryServiceD;
import com.shenbianyun.bosskgpay.utils.*;
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;

/**
 * @author ：张一凡
 * @date ：2023年11月01日 17:36:25
 * @description：易畅行生产个人签约查询
 */

public class YCXTestUserSignQueryServiceJOline extends AbstractJavaSamplerClient {


    public final String CHARSET_UTF_8 = "UTF-8";
    public final Long MER_ID = 1697534870141137L;
    public final String MER_PRIVATE_KEY = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANI9mMMSLm+Baqw2CwTTytpSFOwwHX/udkgyy0agQ5Tgw1GEIeelYlTUg8Qsl1mYK6ftpoV2pUXsPiDmrSQ5gxPs6q6axwzbvGzKqTL+sU+nHdWUnlxolJN4Xfzyr+hzFdHkFRmAL72wbP/Hnpoeo/BiJLDJraZHTqiQsYvQVK3xAgMBAAECgYAE0yUOVPx70pyAFz1pfvLIz9lrEi+bH/3W6lN/622hnQbeeAnPJxx6leXwOpW+mJ9n2yxXI8HnOOS0HJccnbVEVSR5M4KeB08t7G6+ADY42DBAn4//LFTjfqbgvG+X2ECbWBALWbXgMS66v1L22RpnmJGHJsV3vfNrkkFLtAwjgQJBAO7Nxwzr1CxZ2kZyNs1e3s3bdKwk2H2NKC4CktjJF7aIVu0ck9m/DDooCCy/wUQ72fKGz5qmFI58lC1vRR2hoOcCQQDhYUWDrKlg4a5/VePcLX68ehH1/HQz3pj8VhJjYKPTn+6Yb8VZ+ea6ib6+qg1EZ/f49ROEB9KAc9z0IfFc8GdnAkEAxPCv19glgu4XNUG8MGKtHNh/v/gjEmf3WvqEYIR3KfIGvkVzKYCFdPDOzRjXKo6xj3HehIuzKE9VZKL/PRCuwQJBAJvbkZ/qYkOOLgb+1ZFooNEkNZF/oLhSAkfWGedBaGmrmustuDNtvuJW6WKe5IfewjwW9wUCB88u0Ki/ZFNaKJcCQAmyID6pNpPKv9NpIYVXFr0Nvh3nbPd8p5Hyxqtw+qGTa64MiHdWCHV5C5+DXa29wtgUDce6d5OiOTNC9KA8dbY=";
    public final String MER_PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDSPZjDEi5vgWqsNgsE08raUhTsMB1/7nZIMstGoEOU4MNRhCHnpWJU1IPELJdZmCun7aaFdqVF7D4g5q0kOYMT7OqumscM27xsyqky/rFPpx3VlJ5caJSTeF388q/ocxXR5BUZgC+9sGz/x56aHqPwYiSwya2mR06okLGL0FSt8QIDAQAB";
    public final String INTER_KEY = "F44D36620515AA071476355A3E42A192";
    public final String API_VERSION = "V1.0";
    public final String OMS_TEST_URL = "http://gateway.ycxlg.com/ycx/clientapi/clientBusiness/common";

    public static UserSignQueryReqModel proSignQuery = null;

    static Merchant mer = null;



    public String runTestUserSignQueryService() throws Exception {


        mer = new Merchant();
        /*
         * 商户id
         * */
        mer.setMerid(MER_ID);
        /*
         * 商户私钥
         * */
        mer.setPriKey(MER_PRIVATE_KEY);
        /*
         * 商户公钥
         * */
        mer.setPubKey(MER_PUBLIC_KEY);
        /*
         * 商户签名
         * */
        mer.setInterKey(INTER_KEY);


        //公共参数
        RequestMessage rm = new RequestMessage();
        //接口地址
        rm.setFunCode("6011");
        rm.setMerId(mer.getMerid());
        rm.setVersion(API_VERSION);
        rm.setReqId(rm.getFunCode() + System.currentTimeMillis());


        //业务参数：自由职业者签约查询参数
        proSignQuery = new UserSignQueryReqModel();
        proSignQuery.setName("崔方方");
        proSignQuery.setMobile("18001150364");
        proSignQuery.setCardNo(6214830102464327L);
        proSignQuery.setIdCard("412828199310044519");
//        proSignQuery.setProviderId(31720);
        proSignQuery.setProviderId(35304);

        //reqData转json
        String reqData = JsonUtils.toJson(proSignQuery);
        //System.out.println("reqDatajson= " + reqData);


        //reqData加密
        byte[] bs = DESUtils.encrypt(reqData.getBytes(CHARSET_UTF_8), mer.getInterKey());
        String reqDataEncrypt = Base64Utils.encodeToString(bs);
        rm.setReqData(reqDataEncrypt);
        rm.setSign(RSAUtils.sign(reqDataEncrypt, mer.getPriKey()));

        String reqStr = JsonUtils.toJson(rm);
        //System.out.println("请求数据：" + reqStr);


        String resData = HttpClientHelper.sendPost(OMS_TEST_URL, "application/json", reqStr, "POST", CHARSET_UTF_8);
        //System.out.println("返回数据："+resData);
        return resData;
    }



    @Override
    public SampleResult runTest(JavaSamplerContext javaSamplerContext) {
        SampleResult sampleResult = new SampleResult();
        String resData = "";
        TestUserSignQueryServiceD usq = null;

        try {
            sampleResult.sampleStart();

            resData = runTestUserSignQueryService();

            //断言
            JSONObject jsonObject1 = JSONObject.parseObject(resData);
            if (jsonObject1.get("resCode").equals("0000")) {
                sampleResult.setResponseOK();
                sampleResult.setResponseData(true+"", SampleResult.TEXT);
                System.out.println("签约查询结果:" + true);
            } else {
                sampleResult.setSuccessful(false);
                sampleResult.setResponseData(false + " " + jsonObject1.get("resMsg"), SampleResult.TEXT);
                System.out.println("签约查询结果:" + false + " " + jsonObject1.get("resMsg"));
            }
        } catch (Exception e) {
            sampleResult.setSuccessful(false);
            sampleResult.setResponseData(resData, SampleResult.TEXT);
            sampleResult.setResponseMessage(e.toString());

        } finally {
            sampleResult.sampleEnd();
        }
        return sampleResult;
    }

}
